package com.taijia.chapter8;

import java.io.*;

/**
 * TestObjectIO
 * 
 * @author taijia
 * @since 2015年02月01日
 *
 */
public class TestObjectIO {
	public static void main(String[] args) {
		T t = new T();
		t.b = false;
		FileOutputStream fos = null;
		ObjectOutputStream oos = null;
		FileInputStream fis = null;
		ObjectInputStream ois = null;
		String filePath = "E:/myeclipse2014/Workspaces/2014/msb_basic/src/com/taijia/chapter8/TestObjectIO.txt";
		try {
			fos = new FileOutputStream(filePath);
			oos = new ObjectOutputStream(fos);
			oos.writeObject(t);
			oos.flush();
			fis = new FileInputStream(filePath);
			ois = new ObjectInputStream(fis);
			System.out.println(fis.available());
			T t1 = (T)ois.readObject();
			System.out.println(t1.i);
			System.out.println(t1.j);
			System.out.println(t1.d);
			System.out.println(t1.b);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} finally {
			if(null != oos)
				try {
					oos.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}
	}
}

class T implements Serializable{
	int i =0;
	transient int j = 9;
	double d = 2.3;
	boolean b = true;
}
